<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\SetMealOrderSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '订单列表';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="set-meal-order-index col-sm-12" style="margin-top: 15px;">
        <div class="ibox ibox-content">
            <?php echo $this->render('_search', ['model' => $searchModel]); ?>


            <?= GridView::widget([
                'dataProvider' => $dataProvider,
                'tableOptions' => ['class' => 'table table-striped'],
//            'options' => ['class' => 'grid-view', 'style' => 'overflow:auto', 'id' => 'grid'],
                //'filterModel' => $searchModel,
                'columns' => [
                    'id',
                    'sn',
                    'setMeal.title',
                    'num',
                    'sub_date',
                    'time_frame',
//                    'member.username',
                    'name',
                    'phone',
                    'address',
                    [
                        'attribute' => 'status',
                        'value' => function ($m) {
                            return \common\models\SetMealOrder::$statusMap[$m->status];
                        }
                    ],
                    [
                        'attribute' => 'is_use',
                        'value' => function ($m) {
                            return \common\models\SetMealOrder::$isUseMap[$m->is_use];
                        }
                    ],
                    [
                        'attribute' => 'created_at',
                        'value' => function ($m) {
                            return date('Y-m-d H:i:s', $m->created_at);
                        }
                    ],
                    [
                        'class' => 'yii\grid\ActionColumn',
                        'header' => '操作',
                        'headerOptions' => ['width' => '150px'],
                        'template' => '{view} {is-use} {delete}',
                        'buttons' => [
                            'view' => function($url, $model, $key){
                                return Html::a('订单详情', $url,['class' =>'btn btn-outline btn-default btn-xs', 'style' => "margin-top:10px"]);
                            },
                            'is-use' => function ($url, $model, $key) {
                               if($model->status == \common\models\SetMealOrder::STATUS_SUCCESS && $model->is_use == \common\models\SetMealOrder::IS_USE_INIT) {
                                    return Html::a('核销', $url, ['data-confirm' => '你确定要核销吗?', 'class' => 'btn btn-outline btn-info btn-xs', 'style' => "margin-top:10px"]);
                                }
                            },
                            'delete' => function ($url, $model, $key) {
                                return Html::a('删除', $url, ['data-confirm' => '你确定要删除吗?', 'data-method' => 'POST', 'class' => 'btn btn-outline btn-danger btn-xs', 'style' => "margin-top:10px"]);
                            }
                        ],
                    ],
                ],
            ]); ?>
        </div>
    </div>
